home *** CD-ROM | disk | FTP | other *** search
/ AGA Toolkit '97 / The AGA Toolkit '97.iso / text / hyper / ag2txt / ag2txt.c < prev    next >
C/C++ Source or Header  |  1996-09-07  |  4KB  |  164 lines

  1. /******************************************************************************
  2. ** ag2txt.c                                                                  **
  3. **---------------------------------------------------------------------------**
  4. ** AmigaGuide to acsiitext converter                                         **
  5. **---------------------------------------------------------------------------**
  6. ** Version : V 1.0                                                           **
  7. ** Date    : 22.04.1996                                                      **
  8. ** Author  : Stefan Kost                                                     **
  9. ******************************************************************************/
  10.  
  11. /* includes and defines */
  12.  
  13. #include <exec/types.h>
  14. #include <stdio.h>
  15. #include <strings.h>
  16.  
  17. #define MODE_PLAIN    0
  18. #define MODE_ANSI    1
  19.  
  20.  
  21. /* version | revisionscontrol */
  22.  
  23. #define    VERSION        1
  24. #define    REVISION    00
  25. #define    DATE        "__Date__"
  26. #define    VERS        "ag2txt 1.00"
  27. #define    VSTRING        "ag2txt 1.00 ("__DATE__")\n\r"
  28. #define    VERSTAG        "\0$VER: ag2txt 1.00 ("__DATE__")"
  29.  
  30. /* globals */
  31.  
  32. UBYTE VersTag[]    =VERSTAG;                /* Versionsstring */
  33.  
  34. /* functions */
  35.  
  36. void main(int argc,char *argv[])
  37. {
  38.     register UBYTE i;
  39.     char fni[256];
  40.     char fno[256];
  41.     FILE *infile,*outfile;
  42.     UBYTE okay=FALSE;
  43.     UBYTE mode=MODE_PLAIN;
  44.     char links='«',linke='»';
  45.     BYTE lines=1;
  46.     char drive[256],path[256],name[256],ext[256];
  47.     char line[256];
  48.     char c,c2;
  49.     UBYTE nl=TRUE;
  50.  
  51.     printf("\nag2txt V1.0\nby ENSONIC of TRINOMIC\n\n");
  52.     if(argc<2)                                        /* at least one argument is required */
  53.     {
  54.         printf("Usage : ag2txt fname=<name> [mode=<mode> lines=<n> link=<cc>]\n");
  55.         printf("\tfname : file to convert\n");
  56.         printf("\tmode  : plain (default) or ansi\n");
  57.         printf("\tlines : nr of lines inserted between two nodes; default=1\n");
  58.         printf("\tlink  : two charakters for highlighting links; default='«»'\n");
  59.         exit(0);
  60.     }
  61.     for(i=1;i<argc;i++)                                /* parsion options */
  62.     {
  63.         if(!strnicmp(argv[i],"FNAME=",6))
  64.         {
  65.             strcpy(fni,&argv[i][6]);
  66.             strsfn(fni,drive,path,name,ext);
  67.             if(!strlen(path)) sprintf(fno,"%s%s%s.txt",drive,path,name);
  68.             else sprintf(fno,"%s%s/%s.txt",drive,path,name);
  69.             okay=TRUE;
  70.         }
  71.         if(!strnicmp(argv[i],"MODE=",5))
  72.         {
  73.             if(!stricmp(&argv[i][5],"PLAIN")) mode=MODE_PLAIN;
  74.             if(!stricmp(&argv[i][5],"ANSI")) mode=MODE_ANSI;
  75.         }
  76.         if(!strnicmp(argv[i],"LINES=",6))
  77.         {
  78.             lines=atoi(&argv[i][6]);
  79.         }
  80.         if(!strnicmp(argv[i],"LINK=",5))
  81.         {
  82.             links=argv[i][5];
  83.             linke=argv[i][6];
  84.         }
  85.     }
  86.     if(okay)
  87.     {
  88.         printf("converting >%s< to >%s< ...\n",fni,fno);
  89.         if(infile=fopen(fni,"rb"))
  90.         {
  91.             if(outfile=fopen(fno,"wb"))
  92.             {
  93.                 while(!feof(infile))
  94.                 {
  95.                     c=(char)fgetc(infile);
  96.                     if(!feof(infile))
  97.                     {
  98.                         if(c=='@')                                        /* command found */
  99.                         {
  100.                             c2=(char)fgetc(infile);
  101.                             if(c2=='{')                                    /* type 1 : @{...} */
  102.                             {
  103.                                 c2=' ';
  104.                                 while(c2==' ' || c2=='\t') c2=(char)fgetc(infile);        /* white spaces */
  105.                                 if(c2=='"')                                                /* node found */
  106.                                 {
  107.                                     fputc(links,outfile);
  108.                                     c2=' ';
  109.                                     while(c2!='"')
  110.                                     {
  111.                                         c2=(char)fgetc(infile);
  112.                                         if(c2!='"') fputc(c2,outfile);
  113.                                     }
  114.                                     fputc(linke,outfile);
  115.                                 }
  116.                                 while(c2!='}') c2=(char)fgetc(infile);                /* to the closing bracket */
  117.                             }
  118.                             else                                        /* type 2 : @... */
  119.                             {
  120.                                 if(nl)
  121.                                 {
  122.                                     i=1;line[0]=c2;
  123.                                     while(c2!='\n' && i<256)            /* to the end of line */
  124.                                     {
  125.                                         c2=(char)fgetc(infile);
  126.                                         line[i]=c2;
  127.                                         i++;
  128.                                     }
  129.                                     if(i==256) while(c2!='\n') c2=(char)fgetc(infile);
  130. // DEBUG
  131. //    printf("\t>%s<\n",line);
  132. // DEBUG
  133.                                     if(!strnicmp(line,"ENDNODE",7))
  134.                                     {
  135.                                         if(lines>0) for(i=0;i<lines;i++) fputc('\n',outfile);
  136.                                         if(lines<0)
  137.                                         {
  138.                                             fputc('\n',outfile);
  139.                                             for(i=0;i<(-lines);i++) fputc('-',outfile);
  140.                                         }
  141.                                     }
  142.                                 }
  143.                                 else fputc(c,outfile);
  144.                             }
  145.                         }
  146.                         else
  147.                         {
  148.                             fputc(c,outfile);
  149.                             if(c=='\n') nl=TRUE;
  150.                             else nl=FALSE;
  151.                         }
  152.                     }
  153.                 }
  154.                 printf("done !\n\n");
  155.                 fclose(outfile);
  156.             }
  157.             else printf("ERROR : can't open output-file\n");
  158.             fclose(infile);
  159.         }
  160.         else printf("ERROR : can't open input-file\n");
  161.     }
  162.     else printf("ERROR : no inputfile specified\n");
  163. }
  164.